//
//  YWKeepWatchMissionManager.h
//  maintain
//
//  Created by Kyo on 16/2/20.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "YWSingleton.h"
#import "YWKeepWatchMission.h"
#import "YWPatrollineRecord.h"
#import "YWPatrolPointRecord.h"
#import "YWPatrolPicture.h"

@class UIViewController;

typedef NS_ENUM(NSUInteger, YWPatrolPointStatusType) {
    YWPatrolPointStatusTypeUnfinish = 0, // 未巡
    YWPatrolPointStatusTypeFinishNormal = 1, //正常
    YWPatrolPointStatusTypeFinishTrouble = 2, //故障
};

typedef NS_ENUM(NSUInteger, YWKeepWatchJudgeType) {
    YWKeepWatchJudgeTypeMissionHasCancel = 0, //任务已取消
    YWKeepWatchJudgeTypeNotWeekDay = 1, //今天（星期*）不是巡更日
    YWKeepWatchJudgeTypeOutOfMissionTime = 2, //不在任务的执行时间内
    YWKeepWatchJudgeTypeMatch = 3, //匹配
};

typedef NS_ENUM(NSUInteger, YWKeepWatchPointQrcodeResult) {
    YWKeepWatchPointQrcodeResultUnMatch = 0, //不是巡更点
    YWKeepWatchPointQrcodeResultHasPatrol = 1, //已经巡更过的点
    YWKeepWatchPointQrcodeResultNoPatrol = 2, //未巡的点(可以做)
};

static NSString *const KRefreshAssignKeepWatchMissionNotification = @"KRefreshAssignKeepWatchMissionNotification";
static NSString *const KRefreshDeleteKeepWatchMissionNotification = @"KRefreshDeleteKeepWatchMissionNotification";
static NSString *const KRefreshModifyKeepWatchMissionNotification = @"KRefreshModifyKeepWatchMissionNotification";

static NSString *const KRefreshCreatePatrolLineNotification = @"KRefreshCreatePatrolLineNotification";
static NSString *const KRefreshDeletePatrolLineNotification = @"KRefreshDeletePatrolLineNotification";
static NSString *const KRefreshModifyPatrolLineNotification = @"KRefreshModifyPatrolLineNotification";

@interface YWKeepWatchMissionManager : NSObject
YWSingletonH(Manager)

/**
 *  保存巡更任务任务数据
 *
 *  @param keepWatchMission 巡更任务任务模型数组
 */
- (BOOL)updateKeepWatchMissionWithArray:(NSArray*)keepWatchMissions;
/**
 *  更新巡更任务删除状态
 *
 *  @param keepWatchMissionId 巡更任务Id
 *
 *  @return 任务模型
 */
- (BOOL)updateKeepWatchDeleteStatusWithMissionId:(NSInteger)keepWatchMissionId;
/**
 *  所有巡更任务
 *
 *  @return 任务模型数组
 */
- (NSArray*)allKeepWatchMissions;
/**
 *  按页数获取巡更任务
 *
 *  @return 任务模型数组
 */
- (NSArray*)keepWatchMissionsWithPage:(NSInteger)page;
/**
 *  所有巡更任务id（逗号隔开）
 *
 *  @return 任务模型数组
 */
- (NSString*)allKeepWatchMissionIds;
/**
 *  获取巡更任务
 *
 *  @param keepWatchMissionId 巡更任务Id
 *
 *  @return 任务模型
 */
- (YWKeepWatchMission*)keepWatchMissionWithMissionId:(NSInteger)keepWatchMissionId;
/**
 *  获取巡更任务
 *
 *  @param locationId 位置Id
 *
 *  @return 任务模型
 */
- (NSArray*)keepWatchMissionWithLocationId:(NSInteger)locationId;
/**
 *  保存巡更路线记录
 *
 *  @param patrollineRecords 巡更路线记录模型数组
 *
 *  @return 结果
 */
- (BOOL)updatePatrollineRecordWithArray:(NSArray*)patrollineRecords;
/**
 *  更新巡更路线记录（网络数据）
 *
 *  @param patrollineRecords 巡更路线记录模型数组
 *
 *  @return 结果
 */
- (BOOL)updatePatrollineRecordWithNewWorkData:(NSArray*)patrollineRecords;
/**
 *  最新巡更路线记录
 *
 *  @param uniqueTag
 *
 *  @return 结果
 */
- (YWPatrollineRecord*)latestPatrollineRecordWithUniqueTag:(NSString*)uniqueTag;
/**
 *  获取当天完成巡更记录次数
 *
 *  @param patrolLineId 巡更路线id
 *  @param keepWatchMissionId 任务id
 *
 *  @return 记录模型数组
 */
- (NSInteger)todayFinishCountWithPatrolLineId:(NSInteger)patrolLineId keepWatchMissionId:(NSInteger)keepWatchMissionId;

/**
 *  获取巡更路线记录
 *
 *  @param keepWatchMission 巡更任务
 *  @param page 页数
 *
 *  @return 记录模型数组
 */
- (NSArray*)patrollineRecordWithKeepWatchMission:(YWKeepWatchMission*)keepWatchMission page:(NSInteger)page;
/**
 *  获取巡更路线记录
 *
 *  @param page 页数
 *
 *  @return 记录模型数组
 */
- (NSArray*)patrolLineRecordWithPage:(NSInteger)page;
/**
 *  更新记录已读状态
 *
 *  @return 无
 */
- (BOOL)updateReadStatusWithKeepWatchMissionId:(NSInteger)keepWatchMissionId;
/**
 *  保存巡更点记录
 *
 *  @param patrollineRecords 巡更点记录模型数组
 *
 *  @return 结果
 */
- (BOOL)updatePatrolPointRecordWithArray:(NSArray*)patrolPointRecords;
/**
 *  巡更点记录
 *
 *  @param uniqueTag 巡更路线记录标识
 *
 *  @return 记录模型数组
 */
- (NSArray*)patrolPointRecordWithUniqueTag:(NSString*)uniqueTag;
/**
 *  巡更点记录的数量
 *
 *  @param uniqueTag 巡更路线记录标识
 *
 *  @return 记录模型数组
 */
- (NSInteger)countOfPatrolPointRecordWithUniqueTag:(NSString*)uniqueTag;
/**
 *  巡更点记录
 *
 *  @param locationId 位置ID
 *
 *  @return 结果
 */
- (NSArray*)patrolPointRecordWithLocationId:(NSInteger)locationId;
/**
 *  获取上传失败的巡更记录(二维数组)
 *
 *  @return 记录点模型数组
 */
- (NSArray *)patrolPointRecordsWithUploadStatusFail;
/**
 *  获取上传失败的巡更点记录
 *
 *  @return 记录点模型数组
 */
- (NSArray *)uploadFailedPatrolPointRecords;
/**
 *  更新巡更记录的上传状态
 *
 *  @param uploadStatus  上传状态
 *  @param recordId 记录id
 *
 *  @return 结果
 */
- (BOOL)updatePatrolPointRecordUploadStatus:(YWPatrolPointRecordUploadStatus)uploadStatus pointRecordId:(NSString*)recordId;
/**
 *  保存巡更图片
 *
 *  @param patrolPictures 巡更图片模型数组
 *
 *  @return 结果
 */
- (BOOL)updatePatrolPictureWithArray:(NSArray*)patrolPictures;
/**
 *  保存网络请求的巡更点记录图片
 *
 *  @param patrolPictures 巡更图片模型数组
 *
 *  @return 结果
 */
- (BOOL)updatePatrolPictureWithNewWorkData:(NSArray*)patrolPictures;
/**
 *  巡更记录图片或者抄表记录图片
 *
 *  @param recordId 记录Id
 *  @param recordType 图片的类型（巡更或者抄表）
 *
 *  @return 巡更图片模型数组
 */
- (NSArray*)recordPictureWithRecordId:(NSString*)recordId recordType:(YWPictureRecordType)recordType;
/**
 *  所有巡更点
 *
 *  @param patrolLineId 巡更路线id
 *
 *  @return 巡更location模型数组
 */
- (NSArray*)allPatrolLocationWithPatrolLineId:(NSInteger)patrolLineId;
/**
 *  路线下的位置是否存在
 *
 *  @return 记录点模型数组
 */
- (BOOL)isExistLocationWithPatrolLineId:(NSInteger)patrolLineId;
/**
 *  获取巡更点备注
 *
 *  @param locationId 位置
 *
 *  @return 巡更location模型数组
 */
- (NSArray*)patrolLocationNoteWithLocationId:(NSInteger)locationId lineIds:(NSArray*)patrolLineIdArray;
/**
 *  巡更线路对象
 *
 *  @param patrolLineId 巡更路线id
 *
 *  @return 结果
 */
- (YWPatrolLine *)patrolLineWithPatrolLineId:(NSInteger)patrolLineId;
/**
 *  不完整的，需要请求的路线数组
 *
 *  @return 只有id和updateTime的路线对象数组
 */
- (NSArray*)needRequestPatrolLines;
/**
 *  巡更线路预览
 *
 *  @param patrolLine 巡更路线
 *
 *  @return 结果
 */
- (NSArray*)patrolLineDataWithPatrolLine:(YWPatrolLine*)patrolLine;
/**
 *  所有巡更点
 *
 *  @param patrolLineId 巡更路线id
 *  @param keepWatchMissionId 巡更任务id
 *
 *  @return 数组
 */
- (NSArray*)timeLineViewDataWithKeepWatchMission:(YWKeepWatchMission*)keepWatchMission orPatrolLineRecord:(YWPatrollineRecord*)patrolLineRecord;
/**
 *  所有巡更点
 *
 *  @param patrollineRecord 巡更路线记录
 *
 *  @return 数组
 */
- (NSArray*)detailViewTimeLineDataWithPatrollineRecord:(YWPatrollineRecord *)patrollineRecord;
/**
 *  sort
 *
 *  @param locationId 位置id
 *
 *  @return sort
 */
- (NSInteger)sortWithLocationId:(NSInteger)locationId patrolLineId:(NSInteger)patrolLineId;
/**
 *  开始后台上传任务
 *  @param records        记录模型
 *  @param pictures       记录中所有的图片数组
 */
- (void)startUploadRecord:(YWPatrolPointRecord*)pointRecord pictures:(NSArray*)pictures;
/**
 *  上传失败的巡更点记录
 *
 *  @return 记录点模型数组
 */
- (void)uploadFailPatrolPointRecords;
/**
 *  判断扫描的巡更任务
 *
 *  @return 结果
 */
- (YWKeepWatchJudgeType)judgeTypeWithMission:(YWKeepWatchMission*)keepWatchMission;

- (NSString*)typeNameWithJudgeType:(YWKeepWatchJudgeType)judgeType;
/**
 *  判断扫描的巡更点的状态
 *
 *  @return 结果
 */
- (YWKeepWatchPointQrcodeResult)judgeKeepWatchPointWithPatrolLocation:(NSArray* )patrolLocation patrolpointRecord:(NSArray*)patrolpointRecord locationId:(NSInteger)locationId;
/**
 *  新建线路纪录
 *
 *  @return YWPatrollineRecord
 */
- (YWPatrollineRecord *)createLooperRecordWith:(YWKeepWatchMission*)keepWatchMission uniqueTag:(NSString*)uniqueTag;
/**
 *  扫描成功的回调方法
 *
 *  @return YWPatrollineRecord
 */
- (void)qrcodeSuccessWithMission:(YWKeepWatchMission*)keepWatchMission qrcodeId:(NSString*)qrcodeId noQrcodeLocationId:(NSInteger)noQrcodeLocationId uniqueTag:(NSString*)uniqueTag wReader:(UIViewController*)wReader isFromLedger:(BOOL)isFromLedger;

/**
 *  请求楼盘下所有的巡更线路
 *
 *  @return 结果
 */
- (void)requestPatrolLineWithBuildingId:(NSString *)buildingId Complete:(void(^)(NSArray *lineOptionArray))complete;
/**
 *  请求巡更线路的详情
 *
 *  @return 结果
 */
- (void)requestPatrolLineWithPatrolLineId:(NSInteger)lineId Complete:(void(^)(YWPatrolLine *patrolLine))complete;
/**
 *  分配巡更任务
 *
 *  @return 结果
 */
- (void)postKeepWatchMissionWithParams:(NSDictionary*)params Complete:(void(^)(BOOL success))complete;
/**
 *  请求删除巡更任务
 *
 *  @param keepWatchMissionId 任务id
 *
 *  @return 无
 */
- (void)requestDeleteKeepWatchMission:(NSInteger)keepWatchMissionId completeBlock:(void (^)(BOOL))complete;
/**
 *  请求修改巡更任务
 *
 *  @param params 参数
 *
 *  @return 无
 */
- (void)requestModifyKeepWatchMission:(NSDictionary*)params completeBlock:(void (^)(BOOL))complete;
/**
 *  创建巡更路线
 *
 *  @param params 参数
 *
 *  @return 无
 */
- (void)createKeepWatchLine:(NSDictionary*)params completeBlock:(void (^)(NSInteger))complete;
/**
 *  修改巡更路线
 *
 *  @param params 参数
 *
 *  @return 无
 */
- (void)modifyKeepWatchLine:(NSDictionary*)params completeBlock:(void (^)(BOOL))complete;
/**
 *  删除巡更路线
 *
 *  @param params 参数
 *
 *  @return 无
 */
- (void)deleteKeepWatchLineWithLineId:(NSInteger)patrolLineId completeBlock:(void (^)(NSInteger))complete;

/**
 *  请求巡更任务
 *
 *  @return 结果
 */
- (void)requestKeepWatchMissionPage:(NSInteger)page pageSize:(NSInteger)pageSize WithComplete:(void(^)(BOOL success))complete;
/**
 *  请求单条巡更任务
 *
 *  @return 结果
 */
- (void)requestKeepWatchMissionWithMissionId:(NSInteger)missionId Complete:(void(^)(BOOL success))complete;
/**
 *  请求任务的replies，latestRecord
 *
 *  @return 结果
 */
- (void)requestKeepWatchMissionInfo:(NSInteger)keepWatchMissionId complete:(void(^)(BOOL success))complete;
/**
 *  批量查询巡更路线
 *
 *  @return 结果
 */
- (void)requestPatrolLineWithLineArray:(NSArray*)patrolLineArray complete:(void(^)(BOOL success))complete;
/**
 *  请求巡更任务的最新一条的记录
 *
 *  @return 结果
 */
- (void)requestTheLatestLineRecordWithKeepWatchMissionIds:(NSString*)keepWatchMissionIds complete:(void(^)(BOOL success))complete;
/**
 *  请求与我相关的巡更记录
 *
 *  @return 结果
 */
- (void)requestPatrolLineRecordOfMeWithPage:(NSInteger)page pageSize:(NSInteger)pageSize complete:(void(^)(BOOL success))complete;
/**
 *  请求巡更记录
 *
 *  @return 结果
 */
- (void)requestPatrolLineRecordWithPage:(NSInteger)page pageSize:(NSInteger)pageSize keepWatchMissionId:(NSInteger)keepWatchMissionId complete:(void(^)(BOOL success))complete;
/**
 *  请求一条巡更记录详情
 *
 *  @return 结果
 */
- (void)requestPatrolPointRecord:(NSString*)uniqueTag WithComplete:(void(^)(BOOL success))complete;
/**
 *  请求某个位置的巡更记录
 *
 *  @return 结果
 */
- (void)requestPatrolPointRecord:(NSInteger)locationId page:(NSInteger)page pageSize:(NSInteger)pageSize complete:(void(^)(BOOL success))complete;
/**
 *  请求巡查任务状态
 *
 *  @return 结果
 */
- (void)requestKeepWatchMissionStatusWithIds:(NSString *)ids Complete:(void(^)(BOOL success))complete;
/**
 *  扫描匹配巡更任务
 *
 *  @param qrcodeId 二维码id
 *
 *  @return 结果
 */
- (NSArray*)matchKeepWatchMissionsWithQrcodeID:(NSString*)qrcodeId orLocationId:(NSInteger)locationId;
@end
